<?php
declare(strict_types=1);
namespace Field;

class SysCateAccessConst
{
    public const pk='';
    public const index=['CateID','RoleID'];
	public const fields=['CateID','RoleID','AllowRead','AllowThread','AllowPost','AllowAttach','AllowDown'];
	public const comment=['CateID'=>'分类ID','RoleID'=>'权限组','AllowRead'=>'可读','AllowThread'=>'可发帖','AllowPost'=>'可回复','AllowAttach'=>'可上传','AllowDown'=>'可下载'];
	/*
    * @Field CateID
    * @Type int(10) unsigned
    * @Collation 
    * @Null NO
    * @Key PRI
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 分类ID
    */
    public const CateID = 'CateID';
    /*
    * @Field RoleID
    * @Type int(10) unsigned
    * @Collation 
    * @Null NO
    * @Key PRI
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 权限组
    */
    public const RoleID = 'RoleID';
    /*
    * @Field AllowRead
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 可读
    */
    public const AllowRead = 'AllowRead';
    /*
    * @Field AllowThread
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 可发帖
    */
    public const AllowThread = 'AllowThread';
    /*
    * @Field AllowPost
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 可回复
    */
    public const AllowPost = 'AllowPost';
    /*
    * @Field AllowAttach
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 可上传
    */
    public const AllowAttach = 'AllowAttach';
    /*
    * @Field AllowDown
    * @Type int(10) unsigned
    * @Collation 
    * @Null YES
    * @Key 
    * @Default 0
    * @Extra 
    * @Privileges select,insert,update,references
    * @Comment 可下载
    */
    public const AllowDown = 'AllowDown';
}

class SysCateAccessColumns
{
public  int $CateID;
   public  int $RoleID;
   public  int $AllowRead=0;
   public  int $AllowThread=0;
   public  int $AllowPost=0;
   public  int $AllowAttach=0;
   public  int $AllowDown=0;
	public function toArray():array
	{
		return [
'CateID'=>$this->CateID,
    'RoleID'=>$this->RoleID,
    'AllowRead'=>$this->AllowRead,
    'AllowThread'=>$this->AllowThread,
    'AllowPost'=>$this->AllowPost,
    'AllowAttach'=>$this->AllowAttach,
    'AllowDown'=>$this->AllowDown,        ];
	}
}

class SysCateAccessRow
{
	public SysCateAccessColumns $data;
	public function toArray():array
	{
		return $this->data->toArray();
    }

    public function getValue(string $field):string|int|null
    {
        return match ($field){
        'CateID' => $this->data->CateID,
        'RoleID' => $this->data->RoleID,
        'AllowRead' => $this->data->AllowRead,
        'AllowThread' => $this->data->AllowThread,
        'AllowPost' => $this->data->AllowPost,
        'AllowAttach' => $this->data->AllowAttach,
        'AllowDown' => $this->data->AllowDown, default=>null
        };
    }

    public function __construct(array $data)
    {
        $this->data = new SysCateAccessColumns();
        isset($data['CateID']) && $this->data->CateID = (int)$data['CateID'];
           isset($data['RoleID']) && $this->data->RoleID = (int)$data['RoleID'];
           isset($data['AllowRead']) && $this->data->AllowRead = (int)$data['AllowRead'];
           isset($data['AllowThread']) && $this->data->AllowThread = (int)$data['AllowThread'];
           isset($data['AllowPost']) && $this->data->AllowPost = (int)$data['AllowPost'];
           isset($data['AllowAttach']) && $this->data->AllowAttach = (int)$data['AllowAttach'];
           isset($data['AllowDown']) && $this->data->AllowDown = (int)$data['AllowDown'];
    }
}
?>